<template>
  <el-dialog
    :visible.sync="isShow"
    @close="onClose"
    width="800px"
    center
    append-to-body
    title="审核">
      <el-form autocomplete="off" ref="dataForm" label-width="80px" label-position="right" :model="editForm">
        <el-form-item label="审核状态" prop="status" :rules="{required: true,message: '请选择审核状态',trigger: ['blur']}">
          <el-radio-group v-model="editForm.status" @change="editForm.review_result = ''">
            <el-radio :label="2">通过</el-radio>
            <el-radio :label="3">不通过</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核结果" prop="review_result" :rules="{required: true,message: '请输入审核结果',trigger: ['blur']}">
          <el-input
            type="textarea"
            size="medium"
            v-model="editForm.review_result"
            auto-complete="off"
            placeholder="请输入警情描述"
            :autosize="{minRows:5,maxRows:8}"
          ></el-input>
        </el-form-item>
      </el-form>
    <div slot="footer">
      <el-button @click="onClose">取 消</el-button>
      <el-button type="primary" @click="submit" :loading='btnLoading' >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data(){
    return {
      isShow: false,
      btnLoading: false,
      editForm: {
        status: "",
        review_result: ""
      },
      apiFn: null,
    }
  },
  methods:{
    show(id,apiFn){
      this.isShow = true
      this.apiFn = apiFn
      this.id = id
    },
    submit() {
      this.$refs.dataForm.validate().then(_=>{
        this.btnLoading = true;
        if(this.apiFn) {
          this.apiFn(this.editForm,this.id).then(res => {
            this.$message.success("操作成功！")
            this.onClose()
            this.$emit("refresh")
          }).finally(_=>{
            this.btnLoading = false;
          })
        }else{
          // this.$emit(this.editForm)
        }
      })
    },
    onClose() {
      this.editForm = {
        status: "",
        review_result: ""
      }
      this.isShow = false
      this.$nextTick(_=>{
        this.$refs.dataForm.clearValidate()
      })
    }
  }
}
</script>

<style>

</style>